package com.mapstruct.sample;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.mapstruct.factory.Mappers;

public class App {
    public static void main(String[] args) throws Exception {

        StudentExt userExtDO = new StudentExt();
        userExtDO.setRegSource("公众号：Java技术栈");
        userExtDO.setFavorite("写代码");
        userExtDO.setSchool("社会大学");

        Student userDO = new Student();
        userDO.setName("栈长");
        userDO.setSex(1);
        userDO.setAge(18);
        userDO.setBirthday(new Date());
        userDO.setPhone("18888888888");
        userDO.setMarried(true);
        userDO.setRegDate(new Date());
        userDO.setMemo("666");
        userDO.setStudentExt(userExtDO);

        StudentDto userShowDTO = StudentMap.INSTANCE.toUserShowDTO(userDO);
        System.out.println("=====单个对象映射=====");
        System.out.println(userShowDTO);

        List<Student> userDOs = new ArrayList<>();
        Student userDO2 = new Student();
        BeanUtils.copyProperties(userDO, userDO2);// 对象之间的属性赋值,userDO赋值userDO2
        userDO2.setName("栈长2");
        userDOs.add(userDO);
        userDOs.add(userDO2);
        List<StudentDto> userShowDTOs = StudentMap.INSTANCE.toUserShowDTOs(userDOs);
        System.out.println("=====对象列表映射=====");
        userShowDTOs.forEach(System.out::println);
    }
}

